<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'status1';
$return=array();
$merchid=$this->checklogin();
if($_RQ['op']=='status1'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$params['merchid']=$merchid;
	if(!empty($_RQ['clearno'])){
		$params['clearno']=trim($_RQ['clearno']);
		$return['params']['clearno']=$_RQ['clearno'];
	}
	if(isset($_RQ['status']) && $_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
    $fields=array('id','clearno','merchid','realprice','price','status','realpricerate','finalprice');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_supplier_clearing',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$return['status']=array('0'=>'待确认','1'=>'待结算','2'=>'已结算','3'=>'已拒绝');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'list'=>array(
			array('name'=>'clearno','title'=>'结算编号','type'=>'string'),
			array('name'=>'realprice','title'=>'订单应收','type'=>'string'),
			array('name'=>'price','title'=>'订单实收','type'=>'string'),
			array('name'=>'realpricerate','title'=>'抽成后金额','type'=>'string'),
			array('name'=>'finalprice','title'=>'最终打款','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		),'action'=>array(	
			array('type'=>'modal','op'=>'look','title'=>'查看拒绝理由','show'=>array('status'=>3)),
			array('type'=>'modal','op'=>'addcheck','title'=>'重新申请','show'=>array('status'=>3)),
		)),
		'search'=>array(
			array('name'=>'clearno','width'=>15,'title'=>'结算编号','type'=>'string'),
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
		)
	);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/apply_list');
	}else{
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='look'){
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_supplier_clearing',array('id'=>$id));
	$return['item']=$item;
	$htmls=array(
		'type'=>'look',
		'desc'=>'退款拒绝理由',
		'look'=>array(
			array('type'=>'text','title'=>'拒绝理由','name'=>'remark'),			
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='addcheck'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$data=array(
			'content'=>$post['content'],
			'status'=>0,
		);
		pdo_update('jy_supplier_clearing',$data,array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
		exi('提交成功！','','status1');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_supplier_clearing',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'申请审核',
		'edit'=>array(
			array('name'=>'clearno','title'=>'结算编号','type'=>'string','read'=>true),
			array('name'=>'realprice','title'=>'订单应收','type'=>'string','read'=>true),
			array('name'=>'price','title'=>'订单实收','type'=>'string','read'=>true),
			array('name'=>'realpricerate','title'=>'抽成后金额','type'=>'string','read'=>true),
			array('name'=>'finalprice','title'=>'最终打款','type'=>'string','read'=>true),
			array('type'=>'text','title'=>'申请事由','name'=>'content'),		
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='status2'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$params['merchid']=$merchid;
    $fields=array('id','clearno','merchid','realprice','price','status','realpricerate','finalprice');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_supplier_clearing',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$return['status']=array('0'=>'待确认','1'=>'待结算','2'=>'已结算');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			
			
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'list'=>array(
			array('name'=>'clearno','title'=>'结算编号','type'=>'string'),
			array('name'=>'realprice','title'=>'订单应收','type'=>'string'),
			array('name'=>'price','title'=>'订单实收','type'=>'string'),
			array('name'=>'realpricerate','title'=>'抽成后金额','type'=>'string'),
			array('name'=>'finalprice','title'=>'最终打款','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		)),
	);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/apply_list');
	}else{
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='status3'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>2);
	$params['merchid']=$merchid;
    $fields=array('id','clearno','merchid','realprice','price','status','realpricerate','finalprice');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_supplier_clearing',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$return['status']=array('0'=>'待确认','1'=>'待结算','2'=>'已结算');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			
			
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'clearno','title'=>'结算编号','type'=>'string'),
			array('name'=>'realprice','title'=>'订单应收','type'=>'string'),
			array('name'=>'price','title'=>'订单实收','type'=>'string'),
			array('name'=>'realpricerate','title'=>'抽成后金额','type'=>'string'),
			array('name'=>'finalprice','title'=>'最终打款','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		)),
	);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/apply_list');
	}else{
		$return['htmls']=$htmls;
	}
	exi($return);
}
if($_RQ['op']=='status4'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>4);
	$params['merchid']=$merchid;
    $fields=array('id','clearno','merchid','realprice','price','status','realpricerate','finalprice');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_supplier_clearing',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	$return['status']=array('0'=>'待确认','1'=>'待结算','2'=>'已结算');
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			
			
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'clearno','title'=>'结算编号','type'=>'string'),
			array('name'=>'realprice','title'=>'订单应收','type'=>'string'),
			array('name'=>'price','title'=>'订单实收','type'=>'string'),
			array('name'=>'realpricerate','title'=>'抽成后金额','type'=>'string'),
			array('name'=>'finalprice','title'=>'最终打款','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),			
		)),
	);
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/apply_list');
	}else{
		$return['htmls']=$htmls;
	}
	exi($return);
}	
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){	
		$clearing=pdo_get('jy_supplier_clearing',array('id'=>$id));
		if($clearing['status']==0 || $clearing['status']==1){
			pdo_update('jy_weishop_order_goods',array('clearstatus'=>0),array('createtime between'=>array($clearing['starttime'],$clearing['endtime']),'uniacid'=>$_SESSION['uniacid'],'merchid'=>$clearing['merchid']));
		}
		pdo_delete('jy_supplier_clearing',array('id'=>$id,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$clearing=pdo_get('jy_supplier_clearing',array('id'=>$id));
				if($clearing['status']==0 || $clearing['status']==1){
					pdo_update('jy_weishop_order_goods',array('clearstatus'=>0),array('createtime between'=>array($clearing['starttime'],$clearing['endtime']),'uniacid'=>$_SESSION['uniacid'],'merchid'=>$clearing['merchid']));
				}
				pdo_delete('jy_supplier_clearing',array('id'=>$id,'uniacid'=>$_SESSION['uniacid'],'merchid'=>$merchid));
			}
		}
	}
	exi('删除成功！未结算订单可以重新提交结算！');
}
?>